const app = getApp();
Component({
  /**
   * 组件的一些选项
   */
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的对外属性
   */
  properties: {
    bgColor: {
      type: String,
      default: ''
    }, 
    isCustom: {
      type: [Boolean, String],
      default: false
    },
    isBack: {
      type: [Boolean, String],
      default: false
    },
    isTab: {
      type: [Boolean, String],
      default: false
    },
    bgImage: {
      type: String,
      default: ''
    },
    cur_scroll_top:{
      type:Number,
      default:0
    },
    is_index:{
      type:Boolean,
      default:false
    },
	Back:{
	  type:String,
	  default:false
	},
  },
  /**
   * 组件的初始数据
   */
  data: {
    StatusBar: app.globalData.StatusBar || 20,
    CustomBar: app.globalData.CustomBar || 60,
    Custom: app.globalData.Custom || {bottom: 56,height: 32,left: 278,right: 365,top: 24,width: 87},
	home:false
  },
  
  ready() {
	  const pages = getCurrentPages(); 
	  console.log(pages.length);
	  if(pages.length==1){
		  this.setData({
			  home:true
		  })
	  }else{
		  this.setData({
		  	  home:false
		  })
	  }
  },
  methods: {
    BackPage() {
		const pages = getCurrentPages();    //获取当前页面信息栈
		const prevPage = pages[pages.length - 1]     //获取当前页面信息
		const prevPage1 = pages[pages.length - 2]     //获取上一个页面信息
		// console.log(prevPage.route);
	    console.log(pages.length);
		console.log(prevPage);
		console.log(prevPage1);
	 if(pages.length==1){
		 wx.switchTab({
		   url: '/pages/tabbar/index/index',
		 })
		 return;
	 }
	 
	 if(prevPage1!=null){
		 if(prevPage1.route=='packageTab/pages/commitOrder/commitOrder'|| prevPage1.route=='packageTab/pages/exchange/exchange'){
		 wx.navigateBack({
		   delta: 2
		 });
		 return;
		 }
	 }
	  

      wx.navigateBack({
        delta: 1
      });
	  
	  this.triggerEvent('callSomeFun');
    },
    toHome(){
      wx.switchTab({
        url: '/pages/tabbar/index/index',
      })
    },
	chang(){
		console.log(app.globalData.userInfo.is_anchor);
		if(app.globalData.userInfo.is_anchor==2 || app.globalData.userInfo.is_anchor==3){
			wx.navigateTo({
			  url: '/pages/module/createLive/createLive',
			})
		}else{
			wx.navigateTo({
			  url: '/pages/module/hostApply/hostApply',
			})
		}
	},
    onTabClick(event) {
      let index = event.detail.index;
      this.data.tabIndex = index;
      this.triggerEvent('changeTab',{index:index})
    },
    getWord(e){
      this.data.live_key = e.detail.value;
    },
    startSearch(){
      if(!this.data.live_key){
        wx.showToast({
          icon:'none',
          title: '请输入房间号或者房间名称',
        })
        return 
      }
      this.triggerEvent('search',{live_key:this.data.live_key})
    }
  }
})